# encoding:utf-8
from utils.SafeList import SafeList

__author__ = 'Shudong Ma'

import re
import requests

from config.Config import Config
import json
import datetime

# print Config.config_file_path
#
# print datetime.date.today()

#
# str = '{"0600000":{"code": "0600000", "percent": 0.020956, "share": "1", "high": 15.62, "askvol3": 72200, "askvol2": 191160, "askvol5": 297328, "askvol4": 751814, "price": 15.59, "open": 15.15, "bid5": 15.56, "bid4": 15.58, "bid3": 15.59, "bid2": 15.6, "bid1": 15.61, "low": 15.15, "updown": 0.32, "type": "SH", "symbol": "600000", "status": 0, "ask4": 15.65, "bidvol3": 2000, "bidvol2": 200, "bidvol1": 235100, "update": "2015/09/25 15:59:56", "bidvol5": 300, "bidvol4": 3200, "yestclose": 15.27, "askvol1": 169200, "ask5": 15.66, "volume": 136070895, "ask1": 15.62, "name": "\u6d66\u53d1\u94f6\u884c", "ask3": 15.64, "ask2": 15.63, "arrow": "\u2191", "time": "2015/09/25 15:59:52", "turnover": 2096781866}}'
#
# s = json.loads(str)
# print s['0600000']


# str1 = {'last_user_rb_gid': 10105516, 'contractor_id': None, 'last_rebalancing': None, 'view_rebalancing': None, 'sale_flag': False, 'updated_at': 1442207158344L, 'owner': {'profile': '/4716690493', 'constant': None, 'photo_domain': 'http://xavatar.imedao.com/', 'stock_status_count': None, 'stocks_count': None, 'intro': None, 'id': 4716690493L, 'city': '\u57ce\u5e02/\u5730\u533a', 'verified': False, 'province': '\u7701/\u76f4\u8f96\u5e02', 'follow_me': False, 'subscribeable': False, 'name_pinyin': None, 'donate_count': 0, 'followers_count': 1038, 'allow_all_stock': False, 'location': None, 'recommend': None, 'recommend_reason': None, 'type': '1', 'verified_type': 0, 'status': 0, 'verified_description': None, 'description': '', 'friends_count': 145, 'profile_image_url': 'community/20156/1438317783246-1438317787774.jpg,community/20156/1438317783246-1438317787774.jpg!180x180.png,community/20156/1438317783246-1438317787774.jpg!50x50.png,community/20156/1438317783246-1438317787774.jpg!30x30.png', 'step': 'null', 'status_count': 1206, 'stats': None, 'blocking': False, 'name': None, 'remark': None, 'group_ids': None, 'screen_name': '\u4e0d\u8981\u6b3a\u8d1f\u5b89\u54e5\u4e86\u554a', 'url': None, 'gender': 'n', 'st_color': '1', 'following': False, 'last_status_id': 56333824, 'blog_description': None, 'screenname_pinyin': None, 'common_count': 0}, 'last_rb_id': 10105516, 'annualized_gain_rate': 17.61, 'id': 357315, 'net_value': 1.1761, 'last_success_rebalancing': None, 'style': {'color1': '#f05a3c', 'color0': '#f05a3c', 'name': '\u75af\u72c2\u8fc7\u5c71\u8f66', 'degree': 30.0}, 'initial_capital': None, 'commission': None, 'market': 'cn', 'follower_count': 235, 'recommend_reason': None, 'bb_rate': 10.91, 'owner_id': 4716690493L, 'active_flag': True, 'total_gain': 17.61, 'star': 0.0, 'description': None, 'symbol': 'ZH357413', 'performance': None, 'sell_flag': False, 'rank_percent': None, 'contractor_name': None, 'name': '\u6467\u6bc1\u4e00\u5ea7\u9632\u5fa1\u5854', 'daily_gain': 0.0, 'created_at': 1429778641548L, 'tag': None, 'following': False, 'listed_flag': False, 'monthly_gain': 145.76}
# str2 = {'last_user_rb_gid': 10105516, 'contractor_id': None, 'last_rebalancing': None, 'view_rebalancing': None, 'sale_flag': False, 'updated_at': 1442207158344L, 'owner': {'profile': '/4716690493', 'constant': None, 'photo_domain': 'http://xavatar.imedao.com/', 'stock_status_count': None, 'stocks_count': None, 'intro': None, 'id': 4716690493L, 'city': '\u57ce\u5e02/\u5730\u533a', 'verified': False, 'province': '\u7701/\u76f4\u8f96\u5e02', 'follow_me': False, 'subscribeable': False, 'name_pinyin': None, 'donate_count': 0, 'followers_count': 1038, 'allow_all_stock': False, 'location': None, 'recommend': None, 'recommend_reason': None, 'type': '1', 'verified_type': 0, 'status': 0, 'verified_description': None, 'description': '', 'friends_count': 145, 'profile_image_url': 'community/20156/1438317783246-1438317787774.jpg,community/20156/1438317783246-1438317787774.jpg!180x180.png,community/20156/1438317783246-1438317787774.jpg!50x50.png,community/20156/1438317783246-1438317787774.jpg!30x30.png', 'step': 'null', 'status_count': 1206, 'stats': None, 'blocking': False, 'name': None, 'remark': None, 'group_ids': None, 'screen_name': '\u4e0d\u8981\u6b3a\u8d1f\u5b89\u54e5\u4e86\u554a', 'url': None, 'gender': 'n', 'st_color': '1', 'following': False, 'last_status_id': 56333824, 'blog_description': None, 'screenname_pinyin': None, 'common_count': 0}, 'last_rb_id': 10105516, 'annualized_gain_rate': 17.61, 'id': 357315, 'net_value': 1.1761, 'last_success_rebalancing': None, 'style': {'color1': '#f05a3c', 'color0': '#f05a3c', 'name': '\u75af\u72c2\u8fc7\u5c71\u8f66', 'degree': 30.0}, 'initial_capital': None, 'commission': None, 'market': 'cn', 'follower_count': 235, 'recommend_reason': None, 'bb_rate': 10.91, 'owner_id': 4716690493L, 'active_flag': True, 'total_gain': 17.61, 'star': 0.0, 'description': None, 'symbol': 'ZH357413', 'performance': None, 'sell_flag': False, 'rank_percent': None, 'contractor_name': None, 'name': '\u6467\u6bc1\u4e00\u5ea7\u9632\u5fa1\u5854', 'daily_gain': 0.0, 'created_at': 1429778641548L, 'tag': None, 'following': False, 'listed_flag': False, 'monthly_gain': 145.76}
# l = list()
# l.append(str1)
# print str2 in l
#
# class A:
#     def __init__(self):
#         print 'a'
#
# class B(A):
#     def f(self):
#         print ''
#
# b = B()
#
# b.f()
#



# l = ['a',1,4,6]
#
# del(l[2])
#
# for r in l:
#     print r
#
# print datetime.datetime.now().second

# s = SafeList()
# s.append(1)
# s.append('a')
# for row in s:
#     print row
# import service.stockprice.spcrunner as stockprice
# print stockprice.update_mv()

## 股票组合 stock_group补录
from dao.MySqlDAL import MySqlDAL
import time
sqlUtil = MySqlDAL()
res = sqlUtil.get_dimensions_rows("select symbol,stock_group from tb_cube_info where date = '2016-03-13'")
source_data = []
for row in res:
   source_data.append([row['stock_group'],time.time(),row['symbol'],'2016-03-14'])

print sqlUtil.update_many_batch(['stock_group','update_time'],source_data,'tb_cube_info',['symbol','date'],50)
